<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@ taglib prefix="s" uri="/struts-tags" %>


<script type="text/javascript">
function confirmSubmit()
{
var agree=confirm("Are you sure you wish to unassign?");
if (agree)
	return true ;
else
	return false ;
}
	function showHideAttr(divid,size,count)
	{
		
		for(i=1;i<=size;i++)
		{
			if(i==count)
			{
				if(document.getElementById(divid).style.display=="block")
				{
					document.getElementById(divid).style.display="none" ;
				}
				else
				{
					document.getElementById(divid).style.display="block";
				}
			}
			else
			{
				if(document.getElementById("attrId_"+i) != null)
				{
					document.getElementById("attrId_"+i).style.display="none" ;
				}
			}
		}
	}
</script>

<div><h2>Assign Attribute Set To Product</h2></div>

<form name="assignAttributeSet" action="assignAttributeSet" method="post">
	<table>
			<tr><td><b>Attribute Set</b></td>
			<td>
				<input type="hidden" name="productUuid" value="${product.uuid}">
				<input type="hidden" name="p" value="${p}">
				<select name="attributeSetUuId">
				<s:iterator value="attributesets" var="as">	<option value="${as.uuid}">${as.name}</option> </s:iterator>
				</select>
			</td>
		  </tr>
		  <tr>
			<td></td><td><input type="submit" name="assignAttributeSet" value="Assign"></td>
		  </tr>
	</table>
</form>

<div><b>Assigned Attribute Set</b></div>
<table width="100%">
<tr>
<td>
	<table>
		<tr><td width="20%"><b>Id</b></td><td width="60%"><b>Name</b></td><td><b>Un Assign</b></td></tr>
	</table>
</td>
</tr>
<tr>
<td width="80%">
<s:set name="size" value="attributeSetToAv.size()" />
<s:set name="count" value="%{0}" />
<s:iterator status="stat" value="attributeSetToAv" >	
<s:set name="count" value="%{#count + 1}" />
<table>
	<tr><td width="7%">${key.uuid}</td><td width="25%"><a href="#" onclick='showHideAttr("attrId_${count}","${size}","${count}");'>${key.name}</a></td>
		<td width="20%">
			<form name="unassignAttributeSet" action="unassignAttributeSet" method="post" onsubmit="return confirmSubmit()">
				<input type="hidden" name="productUuid" value="${product.uuid}">
				<input type="hidden" name="p" value="${p}">
				<input type="hidden" name="attributeSetUuId" value="${key.uuid}">
				<input type="submit" name="unassign" value="UnAssign">
			</form>
		</td>
	</tr>
</table>

<form name="updateProductAttribute" action="updateProductAttribute" method="post">
<div style="display:none; padding-left: 55px;" id="attrId_${count}">
		<input type="hidden" name="attributeSetUuId" value="${key.uuid}">
		<input type="hidden" name="productUuid" value="${productUuid}">
		<input type="hidden" name="p" value="${p}">

		<div><b>Attributes in Attribute Set ${key.name} </b> </div>
		<table>
			<s:iterator value="value" var="pav">
					<tr><td>${pav.uuid}</td><td>${attribute.name}</td><td>
				<s:if test="attribute.multivalued == true">
						<s:set name="valItr" value="attribute.values"/>
							<s:iterator value="valItr" var="av">
								<!--  	${av.attributeType} -->
								<s:if test="%{#av.attributeType == 'checkbox'}">
										<s:set name="checked" value="ifChecked(#pav.attributeValues,#av)"/>	
									${label} <input type="checkbox" name="chk_${av.uuid}" value="${av.stringValue}" <s:if test="%{#checked == true}">checked</s:if>> 
								</s:if>
								<s:if test="%{(#av.attributeType == 'dropdown')||(#av.attributeType == 'radio')}">
										<s:set name="optionLst" value="getList(#av.stringValue)"/>	
									${label} 
										<s:set name="selected" value="getSelected(product,#av)"/>
										<s:if test="%{#av.attributeType == 'radio'}">
											<s:iterator value="optionLst" var="option">
												${option}&nbsp;	<input type="radio" name="drop_${av.uuid}" <s:if test="%{#selected == #option}">checked</s:if> value="${option}"/>
											</s:iterator>
										</s:if>	
										<s:else>
											<select name="drop_${av.uuid}">
												<option value="">please select</option>
													<s:iterator value="optionLst" var="option">
													<option value="${option}" <s:if test="%{#selected == #option}">selected</s:if>>${option}</option>
											</s:iterator>
										</select>
										</s:else>
								</s:if>
							</s:iterator>
				</s:if>
				<s:else>
						<input type="text" name="txt_${pav.uuid}" value="${pav.value}">
				</s:else>
				</td>
				</tr>
			</s:iterator>
			<tr><td></td><td><input type="submit" name="submit" value="Update AttributeSet ${key.name}"></td><td></td></tr>
		</table>	
</div>	
</form>
</s:iterator>
</td>
</tr>
</table>




<a href="product?p=${p}"><b>Back</b></a>